<template>
  <div>
    <BreakSpace label="客户来电" :containerStyle="{ marginBottom: '0px' }" />
    <TopFilter :list="topFilterList" :labelWidth="90" :cols="3" :isSubmitBtn="false" />
    <BreakSpace label="客户基本信息" :containerStyle="{ marginBottom: '0px' }" />
    <FormPanel ref="form" :list="formList" :labelWidth="90" :cols="3" formType="add" :isSubmitBtn="false" />
    <BreakSpace label="车辆信息" :containerStyle="{ marginBottom: '0px' }" />
    <FilterTable
      ref="table"
      columnsRef="jzyCallcenterAdc"
      :columns="columns"
      :dataSource="list"
      selectionType="single"
      :onRowSelectChange="rowSelectHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <el-button size="small" type="primary">预约安排</el-button>
        <el-button size="small" type="primary">维修历史</el-button>
        <el-button size="small" type="primary">客诉单受理</el-button>
        <el-button size="small" type="primary">投诉历史</el-button>
        <el-button size="small" type="primary">提醒历史</el-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visible" title="客户信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ActionPanel :telPhone="caller" @close="closeActionPanel" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { authority } from '@/utils/authMixin';

import ActionPanel from './actionPanel';

export default {
  name: 'jzyCallcenter',
  components: {
    ActionPanel
  },
  mixins: [dictionary, authority],
  data() {
    const query = this.$route.query || {};
    const caller = query.caller;
    const called = query.called;
    return {
      caller,
      callerInfo: {},
      topFilterList: [
        {
          type: 'INPUT',
          label: '来电号码',
          fieldName: 'caller',
          initialValue: caller,
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '经销商总机号',
          fieldName: 'called',
          initialValue: called,
          placeholder: ''
        }
      ],
      formList: [
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '',
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={this.searchHelper}></el-button>;
          },
          readonly: true
        },
        {
          type: 'INPUT',
          label: '手机',
          fieldName: 'customerPhone',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '电话',
          fieldName: 'phone',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '客户号',
          fieldName: 'customerId',
          placeholder: '',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '地址',
          fieldName: 'address',
          placeholder: '',
          disabled: true,
          selfCols: 2,
          rows: 1
        }
      ],
      list: [],
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '车牌号',
          dataIndex: 'carPlate',
          minWidth: 100,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          minWidth: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '里程',
          dataIndex: 'a3',
          minWidth: 100,
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '品牌',
          dataIndex: 'a4',
          minWidth: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'a5',
          minWidth: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ],
      visible: false
    };
  },
  methods: {
    searchHelper() {
      this.visible = true;
    },
    rowSelectHandle(rows) {},
    closeActionPanel(val, arr) {
      this.visible = val;
      if (!arr) return;
      this.list = arr;
      this.setFormValue(arr[0] || {});
    },
    setFormValue(data) {
      this.formList.forEach(x => {
        x.initialValue = data[x.fieldName];
      });
    }
  }
};
</script>

<style lang="less" scoped></style>
